#include "ssoframe.h"
SsoFrame::SsoFrame(const QByteArray &data):DataReader(data)
{
    readInt(packetSize);packetSize -= 4;
    //TODO: THIS IS WRONG
    readInt(ssoSequenceId);
    readInt(returnCode);
    readBytes(extraData,LengthType::INT,-4);
    readBytes(commandName,LengthType::INT,-4);
    readBytes(outgoingPacketSessionId,LengthType::INT,-4);
    readInt(dataCompressed);
    if(dataCompressed == 0){
        readInt(bodySize);
        if((uint)bodySize != getUnReadSize() && (uint)bodySize != getUnReadSize()+4){
            readAll(body);
            body.push_front(Util::getBytes(bodySize));
        }else readAll(body);
    }else if(dataCompressed == 1){
        skipBytes(4);
        QByteArray data;readAll(data);
        static char tmp[99999];//what the fuck code here???
        long len;
        uncompress((Bytef *)tmp,(uLongf*)&len,(Bytef *)data.data(),data.size());
        if(len == 0)abort();//unzip error
        QByteArray unpressData = QByteArray(tmp,len);
        int size = Util::getData<int>(unpressData);
        if(size == unpressData.size() || size == unpressData.size()+4){
            //todo
            body = unpressData.mid(4,unpressData.size()-4);
        }else body = unpressData;
        //abort();//TODO
    }else if(dataCompressed == 8){
        readAll(body);
    }
}
